var ethinit = function(address, chainId, rpcUrl) {
	if (window.ethereum) {
		return
	}
	// 判断三个参数不能为空，为空的话重新执行
	if(address&&chainId&&rpcUrl){
		// 参数正常的话继续执行
		// 之前的思路是判断创建钱包前前置对象是否创建完毕，发现不可行
		// 现在改成通过try-catch来实现
		try {
			console.log(rpcUrl)
			let config = {
				ethereum: {
					address: address,
					chainId: chainId,
					rpcUrl: rpcUrl
				}
			};
			let ethereum = new trustwallet.Provider(config)
			window.ethereum = Object.assign(ethereum, {
				isMetaMask: true,
				selectedAddress: config.ethereum.address,
				chainId: config.ethereum.chainId,
				networkVersion: '2.0',
				autoRefreshOnNetworkChange: true
			})
			window.ethereum.wallet = {}
			window.ethereum.wallet.address = config.ethereum.address;
			// 至此我们的ETH节点就构建完了
		
			// ETH和TRON还是有区别的，ETH大部分功能都是由包来完成的，只有和节点交互的部分需要处理
			// 而波场的则是全部由钱包对象来处理
			window.ethereum.postMessage = async function(handler, id, data) {
				uni.webView.postMessage({
					data: {
						handler: handler,
						id: id,
						data: data
					}
				});
			}
			uni.webView.postMessage({
				data: {
					handler: "hideloading"
				}
			});
		
		} catch (error) {
			console.log(error)
			setTimeout(function() {
				console.log(address)
				init(address, chainId, rpcUrl)
			}, 300)
		}
	}else{
		setTimeout(function() {
			console.log(address)
			init(address, chainId, rpcUrl)
		}, 300)
	}


}
var urlParams = new URLSearchParams(window.location.search);

// setTimeout(function(){
// 	init(urlParams.get('address'),urlParams.get('chainid'),urlParams.get('fullHost'))

// },1000)
if(urlParams.get('address')&&urlParams.get('chainid')&&urlParams.get('fullHost')){
	setTimeout(function() {
		ethinit(urlParams.get('address'), urlParams.get('chainid'), urlParams.get('fullHost'))
		}, 1000)
	}
	